package com.wdb007.venus.wss.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.wdb007.venus.wss.service.WebSocketServerService;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

@Service("getTimestampService")
public class GetTimestampReqService implements WebSocketServerService {

	private static Logger logger = LoggerFactory.getLogger(GetTimestampReqService.class);
	
	@Override
	public String doService(ChannelHandlerContext ctx, String request) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("message", "操作成功");
		Map<String, Long> innerMap = new HashMap<String, Long>();
		Long tm = System.currentTimeMillis() / 1000 ;
		innerMap.put("timestamp", tm);
		map.put("detail", innerMap);
		String jsonStr = JSON.toJSONString(map);
//		logger.info("获取服务端时间戳返回值: [{}]", jsonStr);
		ctx.channel().writeAndFlush(new TextWebSocketFrame(jsonStr));
		return null;
	}

}
